#!/usr/bin/env bash
set -eo pipefail

declare GLOBAL_GIT_CONFIG_DIR="${HOME}/.git-config"

function main() {
    mkdir -p "${GLOBAL_GIT_CONFIG_DIR}/hooks"
    curl -sk https://gitee.com/lauper/gitcommit/raw/master/commit-template.txt -o "${GLOBAL_GIT_CONFIG_DIR}/commit-template.txt"
    curl -sk https://gitee.com/lauper/gitcommit/raw/master/commit-msg.sh -o "${GLOBAL_GIT_CONFIG_DIR}/hooks/commit-msg"
    chmod +x ${GLOBAL_GIT_CONFIG_DIR}/hooks/commit-msg

    git config --global core.hooksPath "${GLOBAL_GIT_CONFIG_DIR}/hooks"
    git config --global commit.template "${GLOBAL_GIT_CONFIG_DIR}/commit-template.txt"
    echo "ok"
}

main "$@"
